from apache_shenyu_client.config import GatewayConfig
from apache_shenyu_client.api import GatewayProxy
from apache_shenyu_client.register import register_uri, register_all_metadata

"""  
First, modify the configuration according to the project situation, If you do not configure it, you will not be able to use apache_shenyu_client.   
"""
# 全局环境的配置文件，默认本地环境
global_env = "pre"

# test本地环境
test_gateway_host = "192.168.1.82"
test_gateway_port = 9095
test_gateway_server = "http://" + test_gateway_host + ":" + str(test_gateway_port)
test_gateway_username = "admin"
test_gateway_password = "I2finance@830"
# pre环境，可以理解为线上测试环境
pre_gateway_host = "140.207.154.218"
pre_gateway_port = 19095
pre_gateway_server = "http://" + pre_gateway_host + ":" + str(pre_gateway_port)
pre_gateway_username = "admin"
pre_gateway_password = "I2finance@830"
# prod生产环境
prod_gateway_host = "x.x.x.x"
prod_gateway_port = 0
prod_gateway_server = "http://" + prod_gateway_host + ":" + str(prod_gateway_port)
prod_gateway_username = "?"
prod_gateway_password = "?"

# 服务端name
python_server_app_name = "python_app"
# 服务端ip，本机的，替换为你自己的ip
python_server_host = "192.168.100.60"
# 服务端port
python_server_port = 5000
# 服务端注册到网关的路由前缀
python_server_contextPath = "/python-demo"

GatewayConfig.register_type = "http"  # 注册方式使用http
GatewayConfig.test = {
    "servers": test_gateway_host,
    "port": test_gateway_port
}
GatewayConfig.pre = {
    "servers": pre_gateway_host,
    "port": pre_gateway_port
}
GatewayConfig.prod = {
    "servers": prod_gateway_host,
    "port": prod_gateway_port
}
GatewayConfig.uri = {
    "app_name": python_server_app_name,  # app name
    "host": python_server_host,  # python service host
    "port": python_server_port,  # python service port, this service port ois 5000
    "context_path": python_server_contextPath,  # context_path
    "environment": global_env,  # environment
    "rpc_type": "http"  # rpc type
}
if global_env == "test":
    GatewayConfig.register = {
        "register_type": "http",
        "servers": test_gateway_server,
        "props": {
            "username": test_gateway_username,
            "password": test_gateway_password
        }
    }
if global_env == "pre":
    GatewayConfig.register = {
        "register_type": "http",
        "servers": pre_gateway_server,
        "props": {
            "username": pre_gateway_username,
            "password": pre_gateway_password
        }
    }
if global_env == "prod":
    GatewayConfig.register = {
        "register_type": "http",
        "servers": prod_gateway_server,
        "props": {
            "username": prod_gateway_username,
            "password": prod_gateway_password
        }
    }


@register_uri
@register_all_metadata(register_all=True)
def create_app():
    return


def start():
    print("start register python service to gateway ...")
    gt = GatewayProxy()
    uri = gt.register_uri()
    gt.register_metadata(register_all=True)
    print("register python service to gateway success ...")


if __name__ == '__main__':
    start()
